{extend name="Base/base"/}
{block name="body"}
<!-- 标题 -->
    <div class="main-title">
        <h2>新增/编辑商城幻灯片</h2>
    </div>
    <div class="with-padding">


        <div class="tab-wrap" style="margin-bottom: 5px">
            <ul class="nav nav-secondary group_nav">
            </ul>
        </div>
        {empty name="list"}
        <form action="{:url(request()->action(),['action'=>'add'])}" method="post" class="form-horizontal">
            <label class="item-label">编号    </label>
            <div class="controls ">
                <input type="hidden" name="id" value="" class="text input-large form-control" style="width: 400px" placeholder="无需填写" readonly="">
                <p class="lead"></p></div>
            <label class="item-label">图片说明    </label>
            <div class="controls ">
                <input type="text" name="title" value="" class="text input-large form-control" style="width: 400px"></div>
            <label class="item-label">幻灯片图片    </label>
            <div class="controls ">
                <div class="controls">
                    <div id="upload_single_image_image" style="padding-bottom: 5px;" class="webuploader-container">
                        <div class="webuploader-pick">选择图片</div>
                        <div id="rt_rt_1b4t64277n7iv2s1e3vg7d1rtu1" style="position: absolute; top: 0px; left: 0px; width: 64px; height: 28px; overflow: hidden; bottom: auto; right: auto;">
                            <input type="file" name="file" class="webuploader-element-invisible" multiple="multiple"
                                   accept="image/*">
                            <label style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);"></label>
                        </div>
                    </div>
                    <input class="attach" type="hidden" name="image" value="">
                    <div class="upload-img-box">
                        <div class="upload-pre-item popup-gallery">

                        </div>
                    </div>
                </div>
                <!--上传文件-->
                <script>
                    $(function () {
                        var uploader_image= WebUploader.create({
                            // 选完文件后，是否自动上传。
                            auto: true,
                            // swf文件路径
                            swf: "__ROOT__js/ext/webuploader/js/Uploader.swf",
                            // 文件接收服务端。
                            server: "{:url('shop/upload')}",
                            // 选择文件的按钮。可选。
                            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                            pick: '#upload_single_image_image',
                            // 只允许选择图片文件
                            accept: {
                                title: 'Images',
                                extensions: 'gif,jpg,jpeg,bmp,png',
                                mimeTypes: 'image/*'
                            }
                        });
                        uploader_image.on('fileQueued', function (file) {
                            uploader_image.upload();
                        });
                        /*上传成功**/
                        uploader_image.on('uploadSuccess', function (file, data) {
                            //console.log(data);
                            if (data.status) {
                                $("[name='image']").val(data.id);
                                $("[name='image']").parent().find('.upload-pre-item').html(
                                    '<div class="each"><a href="'+ data.url+'" disabled="true" title="点击查看大图"><img src="'+
                                    data.url+'"></a><div class="text-center opacity del_btn" ></div>' +
                                    '<div onclick="admin_image.removeImage($(this),'+data.id+')"  class="text-center del_btn">删除</div></div>');
                                uploader_image.reset();
                            } else {
                                updateAlert(data.info);
                                setTimeout(function () {
                                    $('#top-alert').find('button').click();
                                    $(that).removeClass('disabled').prop('disabled', false);
                                }, 1500);
                            }
                        });
                    })
                </script>
            </div>
            <label class="item-label">链接地址    </label>
            <div class="controls ">选择公众号
                <select name="mp_id">
                    {foreach name="$list.wechat" item="wechat"}
                    <option>{$wechat.public_name}-{$wechat.mp_id}</option>
                    {/foreach}
                </select>
                <input type="text" name="link" value="{$list.link}" class="text input-large form-control" style="width:
                400px"></div>
                <input type="text" name="link" value="" class="text input-large form-control" style="width: 400px"></div>
            <label class="item-label">排序,从大到小    </label>
            <div class="controls ">
                <input type="text" name="sort" value="" class="text input-large form-control" style="width: 400px"></div>
            <label class="item-label">状态    <span class="check-tips">（正常/ 隐藏）</span></label>
            <div class="controls ">
                <label for="id_status_0"> <input id="id_status_0" name="status" value="0" type="radio" checked="">
                    正常</label> &nbsp;&nbsp;&nbsp;&nbsp;
                <label for="id_status_1"> <input id="id_status_1" name="status" value="1" type="radio">
                隐藏</label> &nbsp;&nbsp;&nbsp;&nbsp;
            </div>
            <label class="item-label">创建时间</label>
            <div class="controls ">
                <input type="hidden" name="create_time" value="{php}echo time();{/php}">
                <div class="input-group date">
                    <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                    </div>
                    <input type="text" data-field-name="create_time" class="text form-datetime time form-control pull-left" style="width: 282px" value="2017-01-17 16:31" placeholder="请选择时间">
                </div>
            </div>
            <br>

            <div class="form-item">
                <button class="btn submit-btn ajax-post btn-success" id="submit" type="submit" target-form="form-horizontal">确定</button>  &nbsp;<button onclick="javascript:history.back(-1);return false;" class="btn btn-return">返回</button>  &nbsp;            </div>
        </form>
        {else/}
        <form action="{:url(request()->action(),['action'=>'add'])}" method="post" class="form-horizontal">
            <label class="item-label">编号    </label>
            <div class="controls ">
                <input type="text" name="id" value="{$list.id}" class="text input-large form-control" style="width:
                400px" placeholder="无需填写" readonly="">
                <p class="lead"></p></div>
            <label class="item-label">图片说明    </label>
            <div class="controls ">
                <input type="text" name="title" value="{$list.title}" class="text input-large form-control"
                       style="width: 400px"></div>
            <label class="item-label">幻灯片图片    </label>
            <div class="controls ">
                <div class="controls">
                    <div id="upload_single_image_image" style="padding-bottom: 5px;" class="webuploader-container">
                        <div class="webuploader-pick">选择图片</div>
                        <div id="rt_rt_1b4t64277n7iv2s1e3vg7d1rtu1" style="position: absolute; top: 0px; left: 0px; width: 64px; height: 28px; overflow: hidden; bottom: auto; right: auto;">
                            <input type="file" class="webuploader-element-invisible" multiple="multiple"
                                   accept="image/*">
                            <label style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);"></label>
                        </div>
                    </div>
                    <input class="attach" type="hidden" name="image" value="{$list.image_id}">
                    <div class="upload-img-box">
                        <div class="upload-pre-item popup-gallery">
                            <div class="each">
                                <a><img src="{$list.image}"></a>
                                <div class="text-center opacity del_btn"></div>
                                <div onclick="admin_image.removeImage($(this),{$list.id})" class="text-center del_btn">删除
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--上传文件-->
                <script>
                    $(function () {
                        var uploader_image= WebUploader.create({
                            // 选完文件后，是否自动上传。
                            auto: true,
                            // swf文件路径
                            swf: "__ROOT__js/ext/webuploader/js/Uploader.swf",
                            // 文件接收服务端。
                            server: "{:url('shop/upload')}",
                            // 选择文件的按钮。可选。
                            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                            pick: '#upload_single_image_image',
                            // 只允许选择图片文件
                            accept: {
                                title: 'Images',
                                extensions: 'gif,jpg,jpeg,bmp,png',
                                mimeTypes: 'image/*'
                            }
                        });
                        uploader_image.on('fileQueued', function (file) {
                            uploader_image.upload();
                        });
                        /*上传成功**/
                        uploader_image.on('uploadSuccess', function (file, data) {
                            //console.log(data);
                            if (data.status) {
                                $("[name='image']").val(data.id);
                                $("[name='image']").parent().find('.upload-pre-item').html(
                                    '<div class="each"><a href="'+ data.url+'" disabled="true" title="点击查看大图"><img src="'+
                                    data.url+'"></a><div class="text-center opacity del_btn" ></div>' +
                                    '<div onclick="admin_image.removeImage($(this),'+data.id+')"  class="text-center del_btn">删除</div></div>');
                                uploader_image.reset();
                            } else {
                                updateAlert(data.info);
                                setTimeout(function () {
                                    $('#top-alert').find('button').click();
                                    $(that).removeClass('disabled').prop('disabled', false);
                                }, 1500);
                            }
                        });
                    })
                </script>
            </div>
            <label class="item-label">链接地址    </label>
            <div class="controls ">选择公众号
                <select name="mp_id">
                    {foreach name="$list.wechat" item="wechat"}
                        <option>{$wechat.public_name}-{$wechat.mp_id}</option>
                    {/foreach}
                </select>
                <input type="text" name="link" value="{$list.link}" class="text input-large form-control" style="width:
                400px"></div>
            <label class="item-label">排序,从大到小    </label>
            <div class="controls ">
                <input type="text" name="sort" value="{$list.sort}" class="text input-large form-control" style="width:
                400px"></div>
            <label class="item-label">状态    <span class="check-tips">（正常/ 隐藏）</span></label>
            <div class="controls ">
                <label for="id_stauts_0"><input id="id_stauts_0" name="status" value="0" type="radio" {if
                                                condition="$list.status==0"}checked=""{/if}>正常</label>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <label for="id_stauts_1"> <input id="id_stauts_1" name="status" value="1" type="radio" {if
                                                 condition="$list.status==1"}checked=""{/if}>隐藏</label>
            </div>
            <label class="item-label">创建时间</label>
            <div class="controls ">
                <input type="hidden" name="create_time" value="{$list.create_time}">
                <div class="input-group date">
                    <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                    </div>
                    <input type="text" data-field-name="create_time" class="text form-datetime time form-control pull-left" style="width: 282px" value="{$list.create_time}" placeholder="请选择时间">
                </div>
            </div>
            <br>

            <div class="form-item">
                <button class="btn submit-btn ajax-post btn-success" id="submit" type="submit" target-form="form-horizontal">确定</button>  &nbsp;<button onclick="javascript:history.back(-1);return false;" class="btn btn-return">返回</button>  &nbsp;            </div>
        </form>
        {/empty}
    </div>


</div>
{/block}

{block name="script"}
    <script type="text/javascript">
        $('.form-datetime').datetimepicker({
            language: "zh-CN",
            autoclose: true,
            format: 'yyyy-mm-dd hh:ii'
        });
        $('.form-date').datetimepicker({
            language: "zh-CN",
            minView: 2,
            autoclose: true,
            format: 'yyyy-mm-dd'
        });
        $('.form-time').datetimepicker({
            language: "zh-CN",
            minView: 0,
            startView:1,
            autoclose: true,
            format: 'hh:ii'
        });
        $('.time').change(function () {
            var fieldName = $(this).attr('data-field-name');
            var dateString = $(this).val();
            var date = new Date(dateString);
            var timestamp = date.getTime();
            $('[name=' + fieldName + ']').val(Math.floor(timestamp / 1000));
        });

        $(function () {
            //搜索功能
            $("#search").click(function () {
                var url = $(this).attr('url');
                var query = $('.search-form').find('input').serialize();
                query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
                query = query.replace(/^&/g, '');
                if (url.indexOf('?') > 0) {
                    url += '&' + query;
                } else {
                    url += '?' + query;
                }
                window.location.href = url;
            });
            //回车搜索
            $(".search-input").keyup(function (e) {
                if (e.keyCode === 13) {
                    $("#search").click();
                    return false;
                }
            });
            //导航高亮

            //点击排序
            $('.list_sort').click(function () {
                var url = $(this).attr('url');
                var ids = $('.ids:checked');
                var param = '';
                if (ids.length > 0) {
                    var str = new Array();
                    ids.each(function () {
                        str.push($(this).val());
                    });
                    param = str.join(',');
                }

                if (url != undefined && url != '') {
                    window.location.href = url + '/ids/' + param;
                }
            });
        });
    </script>
{/block}